1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.FileLoader; 26 27 private import gio.AsyncResultIF; 28 private import gio.Cancellable; 29 private import gio.FileIF; 30 private import gio.InputStream; 31 private import glib.ConstructionException; 32 private import glib.ErrorG; 33 private import glib.GException; 34 private import glib.ListSG; 35 private import gobject.ObjectG; 36 private import sourceview.Buffer; 37 private import sourceview.Encoding; 38 private import sourceview.File; 39 private import sourceview.c.functions; 40 public import sourceview.c.types; 41 42 43 /** 44 * Load a file into a GtkSourceBuffer. 45 * 46 * A `GtkSourceFileLoader` object permits to load the contents of a [iface@Gio.File] or a 47 * [class@Gio.InputStream] into a [class@Buffer]. 48 * 49 * A file loader should be used only for one load operation, including errors 50 * handling. If an error occurs, you can reconfigure the loader and relaunch the 51 * operation with [method@FileLoader.load_async]. 52 * 53 * Running a `GtkSourceFileLoader` is an undoable action for the 54 * [class@Buffer]. 55 * 56 * After a file loading, the buffer is reset to the contents provided by the 57 * [iface@Gio.File] or [class@Gio.InputStream], so the buffer is set as “unmodified”, that is, 58 * [method@Gtk.TextBuffer.set_modified] is called with %FALSE. If the contents isn't 59 * saved somewhere (for example if you load from stdin), then you should 60 * probably call [method@Gtk.TextBuffer.set_modified] with %TRUE after calling 61 * [method@FileLoader.load_finish]. 62 */ 63 public class FileLoader : ObjectG 64 { 65 /** the main Gtk struct */ 66 protected GtkSourceFileLoader* gtkSourceFileLoader; 67 68 /** Get the main Gtk struct */ 69 public GtkSourceFileLoader* getFileLoaderStruct(bool transferOwnership = false) 70 { 71 if (transferOwnership) 72 ownedRef = false; 73 return gtkSourceFileLoader; 74 } 75 76 /** the main Gtk struct as a void* */ 77 protected override void* getStruct() 78 { 79 return cast(void*)gtkSourceFileLoader; 80 } 81 82 /** 83 * Sets our main struct and passes it to the parent class. 84 */ 85 public this (GtkSourceFileLoader* gtkSourceFileLoader, bool ownedRef = false) 86 { 87 this.gtkSourceFileLoader = gtkSourceFileLoader; 88 super(cast(GObject*)gtkSourceFileLoader, ownedRef); 89 } 90 91 92 /** */ 93 public static GType getType() 94 { 95 return gtk_source_file_loader_get_type(); 96 } 97 98 /** 99 * Creates a new `GtkSourceFileLoader` object. The contents is read from the 100 * [class@File]'s location. 101 * 102 * If not already done, call [method@File.set_location] before calling this constructor. 103 * The previous location is anyway not needed, because as soon as the file loading begins, 104 * the @buffer is emptied. 105 * 106 * Params: 107 * buffer = the #GtkSourceBuffer to load the contents into. 108 * file = the #GtkSourceFile. 109 * 110 * Returns: a new #GtkSourceFileLoader object. 111 * 112 * Throws: ConstructionException GTK+ fails to create the object. 113 */ 114 public this(Buffer buffer, File file) 115 { 116 auto __p = gtk_source_file_loader_new((buffer is null) ? null : buffer.getBufferStruct(), (file is null) ? null : file.getFileStruct()); 117 118 if(__p is null) 119 { 120 throw new ConstructionException("null returned by new"); 121 } 122 123 this(cast(GtkSourceFileLoader*) __p, true); 124 } 125 126 /** 127 * Creates a new #GtkSourceFileLoader object. The contents is read from @stream. 128 * 129 * Params: 130 * buffer = the #GtkSourceBuffer to load the contents into. 131 * file = the #GtkSourceFile. 132 * stream = the #GInputStream to load, e.g. stdin. 133 * 134 * Returns: a new #GtkSourceFileLoader object. 135 * 136 * Throws: ConstructionException GTK+ fails to create the object. 137 */ 138 public this(Buffer buffer, File file, InputStream stream) 139 { 140 auto __p = gtk_source_file_loader_new_from_stream((buffer is null) ? null : buffer.getBufferStruct(), (file is null) ? null : file.getFileStruct(), (stream is null) ? null : stream.getInputStreamStruct()); 141 142 if(__p is null) 143 { 144 throw new ConstructionException("null returned by new_from_stream"); 145 } 146 147 this(cast(GtkSourceFileLoader*) __p, true); 148 } 149 150 /** 151 * Returns: the #GtkSourceBuffer to load the contents into. 152 */ 153 public Buffer getBuffer() 154 { 155 auto __p = gtk_source_file_loader_get_buffer(gtkSourceFileLoader); 156 157 if(__p is null) 158 { 159 return null; 160 } 161 162 return ObjectG.getDObject!(Buffer)(cast(GtkSourceBuffer*) __p); 163 } 164 165 /** 166 * Returns: the detected compression type. 167 */ 168 public GtkSourceCompressionType getCompressionType() 169 { 170 return gtk_source_file_loader_get_compression_type(gtkSourceFileLoader); 171 } 172 173 /** 174 * Returns: the detected file encoding. 175 */ 176 public Encoding getEncoding() 177 { 178 auto __p = gtk_source_file_loader_get_encoding(gtkSourceFileLoader); 179 180 if(__p is null) 181 { 182 return null; 183 } 184 185 return ObjectG.getDObject!(Encoding)(cast(GtkSourceEncoding*) __p); 186 } 187 188 /** 189 * Returns: the #GtkSourceFile. 190 */ 191 public File getFile() 192 { 193 auto __p = gtk_source_file_loader_get_file(gtkSourceFileLoader); 194 195 if(__p is null) 196 { 197 return null; 198 } 199 200 return ObjectG.getDObject!(File)(cast(GtkSourceFile*) __p); 201 } 202 203 /** 204 * Returns: the #GInputStream to load, or %NULL 205 * if a #GFile is used. 206 */ 207 public InputStream getInputStream() 208 { 209 auto __p = gtk_source_file_loader_get_input_stream(gtkSourceFileLoader); 210 211 if(__p is null) 212 { 213 return null; 214 } 215 216 return ObjectG.getDObject!(InputStream)(cast(GInputStream*) __p); 217 } 218 219 /** 220 * Returns: the #GFile to load, or %NULL 221 * if an input stream is used. 222 */ 223 public FileIF getLocation() 224 { 225 auto __p = gtk_source_file_loader_get_location(gtkSourceFileLoader); 226 227 if(__p is null) 228 { 229 return null; 230 } 231 232 return ObjectG.getDObject!(FileIF)(cast(GFile*) __p); 233 } 234 235 /** 236 * Returns: the detected newline type. 237 */ 238 public GtkSourceNewlineType getNewlineType() 239 { 240 return gtk_source_file_loader_get_newline_type(gtkSourceFileLoader); 241 } 242 243 /** 244 * Loads asynchronously the file or input stream contents into the [class@Buffer]. 245 * 246 * See the [iface@Gio.AsyncResult] documentation to know how to use this 247 * function. 248 * 249 * Params: 250 * ioPriority = the I/O priority of the request. E.g. %G_PRIORITY_LOW, 251 * %G_PRIORITY_DEFAULT or %G_PRIORITY_HIGH. 252 * cancellable = optional #GCancellable object, %NULL to ignore. 253 * progressCallback = function to call back with 254 * progress information, or %NULL if progress information is not needed. 255 * progressCallbackData = user data to pass to @progress_callback. 256 * progressCallbackNotify = function to call on 257 * @progress_callback_data when the @progress_callback is no longer needed, or 258 * %NULL. 259 * callback = a #GAsyncReadyCallback to call when the request is 260 * satisfied. 261 * userData = user data to pass to @callback. 262 */ 263 public void loadAsync(int ioPriority, Cancellable cancellable, GFileProgressCallback progressCallback, void* progressCallbackData, GDestroyNotify progressCallbackNotify, GAsyncReadyCallback callback, void* userData) 264 { 265 gtk_source_file_loader_load_async(gtkSourceFileLoader, ioPriority, (cancellable is null) ? null : cancellable.getCancellableStruct(), progressCallback, progressCallbackData, progressCallbackNotify, callback, userData); 266 } 267 268 /** 269 * Finishes a file loading started with [method@FileLoader.load_async]. 270 * 271 * If the contents has been loaded, the following [class@File] properties will 272 * be updated: the location, the encoding, the newline type and the compression 273 * type. 274 * 275 * Params: 276 * result = a #GAsyncResult. 277 * 278 * Returns: whether the contents has been loaded successfully. 279 * 280 * Throws: GException on failure. 281 */ 282 public bool loadFinish(AsyncResultIF result) 283 { 284 GError* err = null; 285 286 auto __p = gtk_source_file_loader_load_finish(gtkSourceFileLoader, (result is null) ? null : result.getAsyncResultStruct(), &err) != 0; 287 288 if (err !is null) 289 { 290 throw new GException( new ErrorG(err) ); 291 } 292 293 return __p; 294 } 295 296 /** 297 * Sets the candidate encodings for the file loading. 298 * 299 * The encodings are tried in the same order as the list. 300 * 301 * For convenience, @candidate_encodings can contain duplicates. Only the first 302 * occurrence of a duplicated encoding is kept in the list. 303 * 304 * By default the candidate encodings are (in that order in the list): 305 * 306 * 1. If set, the [class@File]'s encoding as returned by [method@File.get_encoding]. 307 * 2. The default candidates as returned by [func@Encoding.get_default_candidates]. 308 * 309 * Params: 310 * candidateEncodings = a list of 311 * #GtkSourceEncoding<!-- -->s. 312 */ 313 public void setCandidateEncodings(ListSG candidateEncodings) 314 { 315 gtk_source_file_loader_set_candidate_encodings(gtkSourceFileLoader, (candidateEncodings is null) ? null : candidateEncodings.getListSGStruct()); 316 } 317 }